package com.cancan.cloud.shop.utils;

import com.cancan.cloud.shop.threadContext.ThreadContextManageUtils;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
@DependsOn("threadContextManageUtils")
public class LogIdManagement {


    public String getId() {
        Object idObj = ThreadContextManageUtils.getThreadContext().getVariable(LogBaseContractValue.KEY_OF_ID);
        String data = idObj == null?null:idObj.toString();
        if(StringUtils.isEmpty(data)){
            data = create();
            setId(data);
        }
        return data;
    }

    public void setId(String id) {
        ThreadContextManageUtils.getThreadContext().setVaiable(LogBaseContractValue.KEY_OF_ID, id);
    }


    public String create(){
        return UUID.randomUUID().toString().replace("-",StringUtils.EMPTY);
    }
}